<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客商名称" prop="custname">
        <el-input
          v-model="queryParams.custname"
          placeholder="请输入客商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签约量/吨" prop="signNum">
        <el-input
          v-model="queryParams.signNum"
          placeholder="请输入签约量/吨"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签约额/万元" prop="signPrice">
        <el-input
          v-model="queryParams.signPrice"
          placeholder="请输入签约额/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交付量/吨" prop="deliverNum">
        <el-input
          v-model="queryParams.deliverNum"
          placeholder="请输入交付量/吨"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产值/万元" prop="outputValue">
        <el-input
          v-model="queryParams.outputValue"
          placeholder="请输入产值/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应结算量/吨" prop="settlementNum">
        <el-input
          v-model="queryParams.settlementNum"
          placeholder="请输入应结算量/吨"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应结算金额/万元" prop="settlementPrice">
        <el-input
          v-model="queryParams.settlementPrice"
          placeholder="请输入应结算金额/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应收金额/万元" prop="amountReceivable">
        <el-input
          v-model="queryParams.amountReceivable"
          placeholder="请输入应收金额/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款金额/万元" prop="amountCollected">
        <el-input
          v-model="queryParams.amountCollected"
          placeholder="请输入收款金额/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建人姓名" prop="createByName">
        <el-input
          v-model="queryParams.createByName"
          placeholder="请输入创建人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人部门" prop="createByDept">
        <el-input
          v-model="queryParams.createByDept"
          placeholder="请输入创建人部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人部门id" prop="createByDeptId">
        <el-input
          v-model="queryParams.createByDeptId"
          placeholder="请输入创建人部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人id" prop="createById">
        <el-input
          v-model="queryParams.createById"
          placeholder="请输入创建人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段1" prop="reserveParam1">
        <el-input
          v-model="queryParams.reserveParam1"
          placeholder="请输入预留字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段2" prop="reserveParam2">
        <el-input
          v-model="queryParams.reserveParam2"
          placeholder="请输入预留字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段3" prop="reserveParam3">
        <el-input
          v-model="queryParams.reserveParam3"
          placeholder="请输入预留字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段4" prop="reserveParam4">
        <el-input
          v-model="queryParams.reserveParam4"
          placeholder="请输入预留字段4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段5" prop="reserveParam5">
        <el-input
          v-model="queryParams.reserveParam5"
          placeholder="请输入预留字段5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['data_upload:uhpc_municipal:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['data_upload:uhpc_municipal:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['data_upload:uhpc_municipal:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['data_upload:uhpc_municipal:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="uhpc_municipalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="productId" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="客商名称" align="center" prop="custname" />
      <el-table-column label="签约量/吨" align="center" prop="signNum" />
      <el-table-column label="签约额/万元" align="center" prop="signPrice" />
      <el-table-column label="交付量/吨" align="center" prop="deliverNum" />
      <el-table-column label="产值/万元" align="center" prop="outputValue" />
      <el-table-column label="应结算量/吨" align="center" prop="settlementNum" />
      <el-table-column label="应结算金额/万元" align="center" prop="settlementPrice" />
      <el-table-column label="应收金额/万元" align="center" prop="amountReceivable" />
      <el-table-column label="收款金额/万元" align="center" prop="amountCollected" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人姓名" align="center" prop="createByName" />
      <el-table-column label="创建人部门" align="center" prop="createByDept" />
      <el-table-column label="创建人部门id" align="center" prop="createByDeptId" />
      <el-table-column label="创建人id" align="center" prop="createById" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态标志" align="center" prop="status" />
      <el-table-column label="预留字段1" align="center" prop="reserveParam1" />
      <el-table-column label="预留字段2" align="center" prop="reserveParam2" />
      <el-table-column label="预留字段3" align="center" prop="reserveParam3" />
      <el-table-column label="预留字段4" align="center" prop="reserveParam4" />
      <el-table-column label="预留字段5" align="center" prop="reserveParam5" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['data_upload:uhpc_municipal:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['data_upload:uhpc_municipal:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改uhpc市政（产品）对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="客商名称" prop="custname">
          <el-input v-model="form.custname" placeholder="请输入客商名称" />
        </el-form-item>
        <el-form-item label="签约量/吨" prop="signNum">
          <el-input v-model="form.signNum" placeholder="请输入签约量/吨" />
        </el-form-item>
        <el-form-item label="签约额/万元" prop="signPrice">
          <el-input v-model="form.signPrice" placeholder="请输入签约额/万元" />
        </el-form-item>
        <el-form-item label="交付量/吨" prop="deliverNum">
          <el-input v-model="form.deliverNum" placeholder="请输入交付量/吨" />
        </el-form-item>
        <el-form-item label="产值/万元" prop="outputValue">
          <el-input v-model="form.outputValue" placeholder="请输入产值/万元" />
        </el-form-item>
        <el-form-item label="应结算量/吨" prop="settlementNum">
          <el-input v-model="form.settlementNum" placeholder="请输入应结算量/吨" />
        </el-form-item>
        <el-form-item label="应结算金额/万元" prop="settlementPrice">
          <el-input v-model="form.settlementPrice" placeholder="请输入应结算金额/万元" />
        </el-form-item>
        <el-form-item label="应收金额/万元" prop="amountReceivable">
          <el-input v-model="form.amountReceivable" placeholder="请输入应收金额/万元" />
        </el-form-item>
        <el-form-item label="收款金额/万元" prop="amountCollected">
          <el-input v-model="form.amountCollected" placeholder="请输入收款金额/万元" />
        </el-form-item>
        <el-form-item label="创建人姓名" prop="createByName">
          <el-input v-model="form.createByName" placeholder="请输入创建人姓名" />
        </el-form-item>
        <el-form-item label="创建人部门" prop="createByDept">
          <el-input v-model="form.createByDept" placeholder="请输入创建人部门" />
        </el-form-item>
        <el-form-item label="创建人部门id" prop="createByDeptId">
          <el-input v-model="form.createByDeptId" placeholder="请输入创建人部门id" />
        </el-form-item>
        <el-form-item label="创建人id" prop="createById">
          <el-input v-model="form.createById" placeholder="请输入创建人id" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserveParam1">
          <el-input v-model="form.reserveParam1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserveParam2">
          <el-input v-model="form.reserveParam2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserveParam3">
          <el-input v-model="form.reserveParam3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserveParam4">
          <el-input v-model="form.reserveParam4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserveParam5">
          <el-input v-model="form.reserveParam5" placeholder="请输入预留字段5" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUhpc_municipal, getUhpc_municipal, delUhpc_municipal, addUhpc_municipal, updateUhpc_municipal } from "@/api/data_upload/uhpc_municipal";

export default {
  name: "Uhpc_municipal",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // uhpc市政（产品）表格数据
      uhpc_municipalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: null,
        custname: null,
        signNum: null,
        signPrice: null,
        deliverNum: null,
        outputValue: null,
        settlementNum: null,
        settlementPrice: null,
        amountReceivable: null,
        amountCollected: null,
        createTime: null,
        createByName: null,
        createByDept: null,
        createByDeptId: null,
        createById: null,
        status: null,
        reserveParam1: null,
        reserveParam2: null,
        reserveParam3: null,
        reserveParam4: null,
        reserveParam5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询uhpc市政（产品）列表 */
    getList() {
      this.loading = true;
      listUhpc_municipal(this.queryParams).then(response => {
        this.uhpc_municipalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        productId: null,
        productName: null,
        custname: null,
        signNum: null,
        signPrice: null,
        deliverNum: null,
        outputValue: null,
        settlementNum: null,
        settlementPrice: null,
        amountReceivable: null,
        amountCollected: null,
        createTime: null,
        createByName: null,
        createByDept: null,
        createByDeptId: null,
        createById: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        status: null,
        reserveParam1: null,
        reserveParam2: null,
        reserveParam3: null,
        reserveParam4: null,
        reserveParam5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.productId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加uhpc市政（产品）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const productId = row.productId || this.ids
      getUhpc_municipal(productId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改uhpc市政（产品）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.productId != null) {
            updateUhpc_municipal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUhpc_municipal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const productIds = row.productId || this.ids;
      this.$modal.confirm('是否确认删除uhpc市政（产品）编号为"' + productIds + '"的数据项？').then(function() {
        return delUhpc_municipal(productIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('data_upload/uhpc_municipal/export', {
        ...this.queryParams
      }, `uhpc_municipal_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
